﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Plumbing;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;
using YArchitech.MEP;
using YArchitech.Revit;

namespace YArchitech.Plumbing
{
	public partial class FormSectorLaySprinkler : System.Windows.Forms.Form
	{
		public FormSectorLaySprinkler(Autodesk.Revit.DB.Document doc)
		{
			this.InitializeComponent();
			this.pboxFamily.SizeMode = PictureBoxSizeMode.Zoom;
			new YJKProcessTools().ShowInTaskbarChange(this);
			base.Location = new System.Drawing.Point(100, 100);
			base.Icon = Resource.YArchitechIcon;
			this.doc = doc;
			this.doc = doc;
			this.InitCurrentProject();
			this.btnHy.BackColor = System.Drawing.Color.White;
			this.currentBtn = 0;
			this.btnproj.BackColor = System.Drawing.Color.Transparent;
			this.panelHy.Visible = true;
			this.panelProj.Visible = false;
			foreach (Element element in YJKElementFilter.GetElementByClass(typeof(PipeType), doc))
			{
				this.cbxPipeType.Items.Add(element.Name);
			}
		}

		private void InitCurrentProject()
		{
			this.tvwProject.Nodes.Add("喷头");
			HyProjectFamily.BingTvwFamilysTwoLevel(HyProjectFamily.GetFamilys(BuiltInCategory.OST_Sprinklers, this.doc), this.tvwProject);
		}

		private void FormSectorLaySprinkler_Load(object sender, EventArgs e)
		{
			this.ReadUserSettedInfo();
			this.InitialSprinklerTypeControls();
			this.txtRadius.Text = this.userSettingInfo.Radius.ToString();
			this.InitialTextBoxInfo();
			this.ShowOrHidePanel();
			this.BandingSprinklerInfo(this.userSettingInfo.FamilyCategory, this.userSettingInfo.FamilyName);
			this.txtOffset.Text = this.userSettingInfo.OffSet.ToString();
			int num = 0;
			IEnumerator enumerator = this.cmbSprinklerType.Items.GetEnumerator();
			{
				while (enumerator.MoveNext())
				{
					if (enumerator.Current.ToString() == this.userSettingInfo.FamilySymbolName)
					{
						break;
					}
					num++;
				}
			}
			this.loadNum++;
			if (num < 0 || num >= this.cmbSprinklerType.Items.Count)
			{
				num = 0;
			}
			if (this.cmbSprinklerType.Items.Count > 0)
			{
				this.cmbSprinklerType.SelectedIndex = num;
			}
		}

		private void ShowOrHidePanel()
		{
			if (this.rdbArc.Checked)
			{
				this.pnlSetting3.Visible = true;
				this.pnlSetting3.Location = new System.Drawing.Point(177, 163);
				this.pnlSetting1.Visible = false;
				this.pnlSetting2.Visible = false;
				this.rdbDistance.Visible = false;
				this.rdbRowCol.Visible = false;
				this.SetArcLayParamPanel();
			}
			if (this.rdbSector.Checked)
			{
				this.pnlSetting3.Visible = false;
				this.pnlSetting3.Location = new System.Drawing.Point(400, 100);
				this.rdbDistance.Visible = true;
				this.rdbRowCol.Visible = true;
				this.SetSectorLayParamPanel();
			}
		}

		private void ReadUserSettedInfo()
		{
			HVACUserSetting hvacuserSetting = new HVACUserSetting();
			this.dicUISetting = hvacuserSetting.GetSectorLaySetting();
			foreach (KeyValuePair<string, string> keyValuePair in this.dicUISetting)
			{
				if (keyValuePair.Key.ToString() == UserSettingName.familyCategory.ToString())
				{
					if (!string.IsNullOrEmpty(keyValuePair.Value))
					{
						this.userSettingInfo.FamilyCategory = Convert.ToInt32(keyValuePair.Value);
					}
					else
					{
						this.userSettingInfo.FamilyCategory = 1;
					}
				}
				if (keyValuePair.Key.ToString() == UserSettingName.familyName.ToString())
				{
					if (!string.IsNullOrEmpty(keyValuePair.Value))
					{
						this.userSettingInfo.FamilyName = keyValuePair.Value;
					}
					else
					{
						this.userSettingInfo.FamilyName = "喷淋头-上喷";
					}
				}
				if (keyValuePair.Key.ToString() == UserSettingName.familySymbolName.ToString())
				{
					if (!string.IsNullOrEmpty(keyValuePair.Value))
					{
						this.userSettingInfo.FamilySymbolName = keyValuePair.Value;
					}
					else
					{
						this.userSettingInfo.FamilySymbolName = "标准";
					}
				}
				if (keyValuePair.Key.ToString() == UserSettingName.drawRange.ToString())
				{
					if (!string.IsNullOrEmpty(keyValuePair.Value))
					{
						this.userSettingInfo.DrawRange = Convert.ToBoolean(keyValuePair.Value);
					}
					else
					{
						this.userSettingInfo.DrawRange = true;
					}
				}
				if (keyValuePair.Key.ToString() == UserSettingName.layStyle.ToString())
				{
					if (!string.IsNullOrEmpty(keyValuePair.Value))
					{
						this.userSettingInfo.LayStyle = keyValuePair.Value;
					}
					else
					{
						this.userSettingInfo.LayStyle = "Arc";
					}
				}
				if (keyValuePair.Key.ToString() == UserSettingName.limitedSector.ToString())
				{
					if (!string.IsNullOrEmpty(keyValuePair.Value))
					{
						this.userSettingInfo.LimitedSector = keyValuePair.Value;
					}
					else
					{
						this.userSettingInfo.LimitedSector = "distance";
					}
				}
				if (keyValuePair.Key.ToString() == UserSettingName.limitedArc.ToString())
				{
					if (!string.IsNullOrEmpty(keyValuePair.Value))
					{
						this.userSettingInfo.LimitedArc = keyValuePair.Value;
					}
					else
					{
						this.userSettingInfo.LimitedArc = "distance";
					}
				}
				if (keyValuePair.Key.ToString() == UserSettingName.divisor.ToString())
				{
					if (!string.IsNullOrEmpty(keyValuePair.Value))
					{
						this.userSettingInfo.Divisor = Convert.ToInt32(keyValuePair.Value);
					}
					else
					{
						this.userSettingInfo.Divisor = 50;
					}
				}
				if (keyValuePair.Key.ToString() == UserSettingName.drawLength.ToString())
				{
					if (!string.IsNullOrEmpty(keyValuePair.Value))
					{
						this.userSettingInfo.DrawLength = Convert.ToDouble(keyValuePair.Value);
					}
					else
					{
						this.userSettingInfo.DrawLength = 0.2;
					}
				}
				if (keyValuePair.Key.ToString() == UserSettingName.dangerLevel.ToString())
				{
					if (!string.IsNullOrEmpty(keyValuePair.Value))
					{
						this.userSettingInfo.DangerLevel = keyValuePair.Value;
					}
					else
					{
						this.userSettingInfo.DangerLevel = "轻危险级";
					}
				}
				if (keyValuePair.Key.ToString() == UserSettingName.sectorCol.ToString())
				{
					if (!string.IsNullOrEmpty(keyValuePair.Value))
					{
						this.userSettingInfo.SectorCol = Convert.ToInt32(keyValuePair.Value);
					}
					else
					{
						this.userSettingInfo.SectorCol = 2;
					}
				}
				if (keyValuePair.Key.ToString() == UserSettingName.sectorRow.ToString())
				{
					if (!string.IsNullOrEmpty(keyValuePair.Value))
					{
						this.userSettingInfo.SectorRow = Convert.ToInt32(keyValuePair.Value);
					}
					else
					{
						this.userSettingInfo.SectorRow = 2;
					}
				}
				if (keyValuePair.Key.ToString() == UserSettingName.sectorRatio.ToString())
				{
					if (!string.IsNullOrEmpty(keyValuePair.Value))
					{
						this.userSettingInfo.SectorRatio = Convert.ToDouble(keyValuePair.Value);
					}
					else
					{
						this.userSettingInfo.SectorRatio = 0.5;
					}
				}
				if (keyValuePair.Key.ToString() == UserSettingName.arcNum.ToString())
				{
					if (!string.IsNullOrEmpty(keyValuePair.Value))
					{
						this.userSettingInfo.ArcNum = Convert.ToInt32(keyValuePair.Value);
					}
					else
					{
						this.userSettingInfo.ArcNum = 3;
					}
				}
				if (keyValuePair.Key.ToString() == UserSettingName.arcRatio.ToString())
				{
					if (!string.IsNullOrEmpty(keyValuePair.Value))
					{
						this.userSettingInfo.ArcRatio = Convert.ToDouble(keyValuePair.Value);
					}
					else
					{
						this.userSettingInfo.ArcRatio = 0.5;
					}
				}
				if (keyValuePair.Key.ToString() == UserSettingName.arcDistance.ToString())
				{
					if (!string.IsNullOrEmpty(keyValuePair.Value))
					{
						this.userSettingInfo.ArcDistance = Convert.ToInt32(keyValuePair.Value);
					}
					else
					{
						this.userSettingInfo.ArcDistance = 3000;
					}
				}
				if (keyValuePair.Key.ToString() == UserSettingName.arcSide.ToString())
				{
					if (!string.IsNullOrEmpty(keyValuePair.Value))
					{
						this.userSettingInfo.ArcSide = Convert.ToInt32(keyValuePair.Value);
					}
					else
					{
						this.userSettingInfo.ArcSide = 2000;
					}
				}
				if (keyValuePair.Key.ToString() == UserSettingName.offSet.ToString())
				{
					if (!string.IsNullOrEmpty(keyValuePair.Value))
					{
						this.userSettingInfo.OffSet = Convert.ToDouble(keyValuePair.Value);
					}
					else
					{
						this.userSettingInfo.OffSet = 2.7;
					}
				}
				if (keyValuePair.Key.ToString() == UserSettingName.radius.ToString())
				{
					if (!string.IsNullOrEmpty(keyValuePair.Value))
					{
						this.userSettingInfo.Radius = Convert.ToDouble(keyValuePair.Value);
					}
					else
					{
						this.userSettingInfo.Radius = 3.1;
					}
				}
				if (keyValuePair.Key.ToString() == UserSettingName.kCoffie.ToString())
				{
					if (!string.IsNullOrEmpty(keyValuePair.Value))
					{
						this.userSettingInfo.KCoffie = Convert.ToDouble(keyValuePair.Value);
					}
					else
					{
						this.userSettingInfo.KCoffie = 80.0;
					}
				}
				if (keyValuePair.Key.ToString() == UserSettingName.isConn.ToString())
				{
					if (!string.IsNullOrEmpty(keyValuePair.Value))
					{
						this.userSettingInfo.IsConn = Convert.ToInt32(keyValuePair.Value);
					}
					else
					{
						this.userSettingInfo.IsConn = 0;
					}
				}
				if (keyValuePair.Key.ToString() == UserSettingName.pipeType.ToString())
				{
					if (!string.IsNullOrEmpty(keyValuePair.Value))
					{
						this.userSettingInfo.PipeType = Convert.ToInt32(keyValuePair.Value);
					}
					else
					{
						this.userSettingInfo.PipeType = 8;
					}
				}
			}
		}

		private void InitialSprinklerTypeControls()
		{
			switch (this.userSettingInfo.FamilyCategory)
			{
			case 1:
				this.rdbUpSprinkler.Checked = true;
				this.rdbWater.Checked = false;
				this.rdbDownSprinkler.Checked = false;
				break;
			case 2:
				this.rdbUpSprinkler.Checked = false;
				this.rdbWater.Checked = false;
				this.rdbDownSprinkler.Checked = true;
				break;
			case 4:
				this.rdbUpSprinkler.Checked = false;
				this.rdbWater.Checked = true;
				this.rdbDownSprinkler.Checked = false;
				break;
			}
			this.listDangerLevels.Add(new DangerItem("轻危险级", 4400.0, 4400.0, 2400.0, 2200.0, 2200.0, 3100.0));
			this.listDangerLevels.Add(new DangerItem("中危险级I", 3600.0, 3600.0, 2400.0, 1800.0, 1800.0, 2500.0));
			this.listDangerLevels.Add(new DangerItem("中危险级II", 3400.0, 3400.0, 2400.0, 1700.0, 1700.0, 2400.0));
			this.listDangerLevels.Add(new DangerItem("严重危险级I", 3000.0, 3000.0, 2400.0, 1500.0, 1500.0, 2100.0));
			this.listDangerLevels.Add(new DangerItem("严重危险级Ⅱ", 3000.0, 3000.0, 2400.0, 1500.0, 1500.0, 2100.0));
			this.listDangerLevels.Add(new DangerItem("仓库危险级I", 3000.0, 3000.0, 2400.0, 1500.0, 1500.0, 2100.0));
			this.listDangerLevels.Add(new DangerItem("仓库危险级Ⅱ", 3000.0, 3000.0, 2400.0, 1500.0, 1500.0, 2100.0));
			this.listDangerLevels.Add(new DangerItem("仓库危险级Ⅲ", 3000.0, 3000.0, 2400.0, 1500.0, 1500.0, 2100.0));
		}

		private void InitialTextBoxInfo()
		{
			this.txtOffset.Text = this.userSettingInfo.OffSet.ToString();
			this.txtRadius.Text = this.userSettingInfo.Radius.ToString();
			this.txtKCoff.Text = this.userSettingInfo.KCoffie.ToString();
			if (this.userSettingInfo.DrawRange)
			{
				this.ckbDraw.Checked = true;
			}
			else
			{
				this.ckbDraw.Checked = false;
			}
			this.txtRowNum.Text = this.userSettingInfo.SectorRow.ToString();
			this.txtColNum.Text = this.userSettingInfo.SectorCol.ToString();
			this.txtRatio.Text = this.userSettingInfo.SectorRatio.ToString();
			this.txtPLDistance.Text = this.userSettingInfo.DrawLength.ToString();
			this.txtArcDistance.Text = this.userSettingInfo.ArcDistance.ToString();
			this.txtArcFirstDistance.Text = this.userSettingInfo.ArcSide.ToString();
			this.txtSpNum.Text = this.userSettingInfo.ArcNum.ToString();
			this.txtArcRatio.Text = this.userSettingInfo.ArcRatio.ToString();
			this.cmbDisMuilty.SelectedIndex = ((this.userSettingInfo.Divisor == 50) ? 0 : 1);
			this.cmbRCMultiple.SelectedIndex = ((this.userSettingInfo.Divisor == 50) ? 0 : 1);
			if (this.userSettingInfo.LayStyle == "Arc")
			{
				this.rdbArc.Checked = true;
				this.rdbSector.Checked = false;
				if (this.userSettingInfo.LimitedArc == "distance")
				{
					this.rdbArcDis.Checked = true;
					this.rdbNum.Checked = false;
				}
				else
				{
					this.rdbArcDis.Checked = false;
					this.rdbNum.Checked = true;
				}
			}
			else
			{
				this.rdbSector.Checked = true;
				this.rdbArc.Checked = false;
				if (this.userSettingInfo.LimitedSector == "distance")
				{
					this.rdbRowCol.Checked = false;
					this.rdbDistance.Checked = true;
				}
				else
				{
					this.rdbRowCol.Checked = true;
					this.rdbDistance.Checked = false;
				}
			}
			this.cmbDangerLevel.DataSource = this.listDangerLevels;
			this.cmbDangerLevel.DisplayMember = "Name";
			this.cmbDangerLevel.ValueMember = "MoreDistanceRow";
			this.cmbDangerLevel.SelectedText = this.userSettingInfo.DangerLevel;
			if (this.userSettingInfo.DrawRange)
			{
				this.ckbDraw.Checked = true;
			}
			else
			{
				this.ckbDraw.Checked = false;
			}
			if (this.userSettingInfo.IsConn == 0)
			{
				this.rdoConn.Checked = true;
				this.rdoUnConn.Checked = false;
			}
			else
			{
				this.rdoConn.Checked = false;
				this.rdoUnConn.Checked = true;
			}
			try
			{
				this.cbxPipeType.SelectedIndex = this.userSettingInfo.PipeType;
			}
			catch (Exception)
			{
				this.cbxPipeType.SelectedIndex = 0;
			}
		}

		private void SetArcLayParamPanel()
		{
			if (this.rdbArcDis.Checked)
			{
				this.txtArcDistance.Enabled = true;
				this.txtArcFirstDistance.Enabled = true;
				this.txtArcRatio.Enabled = false;
				this.txtSpNum.Enabled = false;
				this.userSettingInfo.LimitedArc = "distance";
			}
			if (this.rdbNum.Checked)
			{
				this.txtArcDistance.Enabled = false;
				this.txtArcFirstDistance.Enabled = false;
				this.txtArcRatio.Enabled = true;
				this.txtSpNum.Enabled = true;
				this.userSettingInfo.LimitedArc = "rowCol";
			}
		}

		private void SetSectorLayParamPanel()
		{
			if (this.rdbRowCol.Checked)
			{
				this.pnlSetting1.Visible = false;
				this.pnlSetting2.Visible = true;
			}
			if (this.rdbDistance.Checked)
			{
				this.pnlSetting1.Visible = true;
				this.pnlSetting2.Visible = false;
			}
		}

		private void rdbArc_CheckedChanged(object sender, EventArgs e)
		{
			this.SetPannelVisible();
			if (this.rdbArc.Checked)
			{
				this.userSettingInfo.LayStyle = "Arc";
				if (this.userSettingInfo.LimitedArc == "distance")
				{
					this.rdbArcDis.Checked = true;
					this.rdbNum.Checked = false;
				}
				else
				{
					this.rdbArcDis.Checked = false;
					this.rdbNum.Checked = true;
				}
				this.rdoConn.Enabled = false;
				this.rdoUnConn.Enabled = false;
				this.cbxPipeType.Enabled = false;
				this.txtPLDistance.Enabled = false;
			}
			else
			{
				this.userSettingInfo.LayStyle = "Sector";
				if (this.userSettingInfo.LimitedSector == "distance")
				{
					this.rdbRowCol.Checked = false;
					this.rdbDistance.Checked = true;
				}
				else
				{
					this.rdbRowCol.Checked = true;
					this.rdbDistance.Checked = false;
				}
				this.rdoConn.Enabled = true;
				this.rdoUnConn.Enabled = true;
				if (this.rdoConn.Checked)
				{
					this.cbxPipeType.Enabled = true;
					this.txtPLDistance.Enabled = true;
				}
			}
			this.ShowOrHidePanel();
			this.Refresh();
		}

		private void SetPannelVisible()
		{
			this.pnlSetting1.Visible = false;
			this.pnlSetting2.Visible = false;
			this.pnlSetting3.Visible = false;
		}

        private void SetPannelLocation(System.Windows.Forms.Panel pannel, int locX, int locY)
		{
			pannel.Location = new System.Drawing.Point(locX, locY);
		}

		private void rdbDistance_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rdbRowCol.Checked)
			{
				this.userSettingInfo.LimitedSector = "rowCol";
			}
			if (this.rdbDistance.Checked)
			{
				this.userSettingInfo.LimitedSector = "distance";
			}
			this.SetSectorLayParamPanel();
		}

		private void rdbArcDis_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rdbArcDis.Checked)
			{
				this.userSettingInfo.LimitedSector = "distance";
			}
			if (this.rdbNum.Checked)
			{
				this.userSettingInfo.LimitedSector = "rowCol";
			}
			this.SetArcLayParamPanel();
		}

		private void ckbDraw_CheckedChanged(object sender, EventArgs e)
		{
			if (this.ckbDraw.Checked)
			{
				this.userSettingInfo.DrawRange = true;
				return;
			}
			this.userSettingInfo.DrawRange = false;
		}

		private void BandingSprinklerInfo(int categoryId, string fName)
		{
			this.familyInfos = this.dataReader.GetAllNameAndImage("Sprinkler", categoryId);
			string text = "";
			foreach (ListItem listItem in this.familyInfos)
			{
				this.userSettingInfo.FamilyName = listItem.Name;
				this.familyID = Convert.ToInt32(listItem.Tag);
				text = listItem.Value;
				if (listItem.Name == fName)
				{
					this.userSettingInfo.FamilyName = listItem.Name;
					this.familyID = Convert.ToInt32(listItem.Tag);
					text = listItem.Value;
					break;
				}
			}
			this.txtFamilyName.Text = this.userSettingInfo.FamilyName;
			if (File.Exists(text))
			{
				this.pboxFamily.Image = Image.FromFile(text);
			}
		}

		private void txtFamilyName_TextChanged(object sender, EventArgs e)
		{
			this.TxtFamilyNameTextChanged();
		}

		private void TxtFamilyNameTextChanged()
		{
			if (this.familyInfos.Count > 0)
			{
				foreach (ListItem listItem in this.familyInfos)
				{
					if (this.txtFamilyName.Text.Trim() == listItem.Name)
					{
						this.familyID = int.Parse(listItem.Tag.ToString());
					}
				}
			}
			foreach (ListItem listItem2 in this.dataReader.GetInfoById("Sprinkler", this.familyID))
			{
				if (listItem2.Name == "FamilySymbol")
				{
					this.BandingFamilySybol(listItem2.Value, this.userSettingInfo.FamilySymbolName);
				}
			}
		}

		private void BandingFamilySybol(string fsArray, string recordFSName)
		{
			this.cmbSprinklerType.Items.Clear();
			foreach (string text in fsArray.Split(new char[]
			{
				';',
				',',
				'，'
			}))
			{
				if (text.Trim() != "")
				{
					this.cmbSprinklerType.Items.Add(text);
				}
			}
			if (this.cmbSprinklerType.Items != null && this.cmbSprinklerType.Items.Count > 0 && this.loadNum > 0)
			{
				int num = 0;
				IEnumerator enumerator = this.cmbSprinklerType.Items.GetEnumerator();
				{
					while (enumerator.MoveNext())
					{
						if (enumerator.Current.ToString() == this.userSettingInfo.FamilySymbolName)
						{
							break;
						}
						num++;
					}
				}
				if (num == this.cmbSprinklerType.Items.Count)
				{
					num = 0;
				}
				if (num < 0 || num >= this.cmbSprinklerType.Items.Count)
				{
					num = 0;
				}
				if (this.cmbSprinklerType.Items.Count > 0)
				{
					this.cmbSprinklerType.SelectedIndex = num;
					this.userSettingInfo.FamilySymbolName = this.cmbSprinklerType.Items[0].ToString();
				}
			}
		}

		private void pboxFamily_Click(object sender, EventArgs e)
		{
			this.userSettingInfo.FamilyName = this.txtFamilyName.Text;
			FormChooseSprinkler formChooseSprinkler = new FormChooseSprinkler(this.userSettingInfo.FamilyName, this.familyInfos);
			formChooseSprinkler.Text = "选择喷头";
			formChooseSprinkler.Owner = this;
			if (formChooseSprinkler.ShowDialog() == DialogResult.OK && this.userSettingInfo.FamilyName != formChooseSprinkler.ImageName && formChooseSprinkler.ImageName != "")
			{
				this.userSettingInfo.FamilyName = formChooseSprinkler.ImageName;
				this.txtFamilyName.Text = this.userSettingInfo.FamilyName;
				foreach (ListItem listItem in this.familyInfos)
				{
					if (listItem.Name == this.userSettingInfo.FamilyName)
					{
						this.familyID = int.Parse(listItem.Tag.ToString());
						break;
					}
				}
				this.BandingSprinklerInfo(this.userSettingInfo.FamilyCategory, this.userSettingInfo.FamilyName);
			}
		}

		private void rdbWater_CheckedChanged(object sender, EventArgs e)
		{
			RadioButton radioButton = sender as RadioButton;
			if (radioButton.Name == "rdbUpSprinkler")
			{
				this.BandingSprinklerInfo(1, this.userSettingInfo.FamilyName);
				this.userSettingInfo.FamilyCategory = 1;
				return;
			}
			if (radioButton.Name == "rdbDownSprinkler")
			{
				this.BandingSprinklerInfo(2, this.userSettingInfo.FamilyName);
				this.userSettingInfo.FamilyCategory = 2;
				return;
			}
			if (radioButton.Name == "rdbWater")
			{
				this.BandingSprinklerInfo(4, this.userSettingInfo.FamilyName);
				this.userSettingInfo.FamilyCategory = 4;
				return;
			}
			this.BandingSprinklerInfo(1, this.userSettingInfo.FamilyName);
			this.userSettingInfo.FamilyCategory = 1;
		}

		private void cmbDangerLevel_SelectedIndexChanged(object sender, EventArgs e)
		{
			DangerItem dangerItem = this.cmbDangerLevel.SelectedItem as DangerItem;
			this.txtRowDis.Text = dangerItem.MoreDistanceRow.ToString();
			this.txtColDis.Text = dangerItem.MoreDistanceCol.ToString();
			this.txtMinDis.Text = dangerItem.LessDistance.ToString();
			this.txtRowSide.Text = dangerItem.SideDistanceRow.ToString();
			this.txtColSide.Text = dangerItem.SideDistanceCol.ToString();
		}

		private void TextChange(object sender, EventArgs e)
		{
			System.Windows.Forms.TextBox textBox = sender as System.Windows.Forms.TextBox;
			if (!this.BeNumber(textBox.Text))
			{
				return;
			}
			string name = textBox.Name;
			if ((name == "txtRowNum" || name == "txtColNum" || name == "txtArcDistance" || name == "txtArcFirstDistance" || name == "txtSpNum") && !this.BeInteger(textBox.Text))
			{
				return;
			}
			name = textBox.Name;
			uint num = YArchitech.Revit.PrivateImplementationDetails.ComputeStringHash(name);
			if (num <= 1905503892u)
			{
				if (num <= 745439394u)
				{
					if (num != 126510829u)
					{
						if (num != 745439394u)
						{
							return;
						}
						if (!(name == "txtArcFirstDistance"))
						{
							return;
						}
						this.userSettingInfo.ArcSide = Convert.ToInt32(textBox.Text);
						return;
					}
					else
					{
						if (!(name == "txtRadius"))
						{
							return;
						}
						this.userSettingInfo.Radius = Convert.ToDouble(textBox.Text);
						return;
					}
				}
				else if (num != 1247899082u)
				{
					if (num != 1660662284u)
					{
						if (num != 1905503892u)
						{
							return;
						}
						if (!(name == "txtOffset"))
						{
							return;
						}
						this.userSettingInfo.OffSet = Convert.ToDouble(textBox.Text);
						return;
					}
					else
					{
						if (!(name == "txtSpNum"))
						{
							return;
						}
						this.userSettingInfo.ArcNum = Convert.ToInt32(textBox.Text);
						return;
					}
				}
				else
				{
					if (!(name == "txtRatio"))
					{
						return;
					}
					this.userSettingInfo.SectorRatio = Convert.ToDouble(textBox.Text);
					return;
				}
			}
			else if (num <= 2695252219u)
			{
				if (num != 2320115276u)
				{
					if (num != 2455206200u)
					{
						if (num != 2695252219u)
						{
							return;
						}
						if (!(name == "txtRowNum"))
						{
							return;
						}
						this.userSettingInfo.SectorRow = Convert.ToInt32(textBox.Text);
						return;
					}
					else
					{
						if (!(name == "txtArcRatio"))
						{
							return;
						}
						this.userSettingInfo.ArcRatio = Convert.ToDouble(textBox.Text);
						return;
					}
				}
				else
				{
					if (!(name == "txtPLDistance"))
					{
						return;
					}
					this.userSettingInfo.DrawLength = Convert.ToDouble(textBox.Text);
					return;
				}
			}
			else if (num != 2739456642u)
			{
				if (num != 3011848981u)
				{
					if (num != 3818623342u)
					{
						return;
					}
					if (!(name == "txtArcDistance"))
					{
						return;
					}
					this.userSettingInfo.ArcDistance = Convert.ToInt32(textBox.Text);
					return;
				}
				else
				{
					if (!(name == "txtColNum"))
					{
						return;
					}
					this.userSettingInfo.SectorCol = Convert.ToInt32(textBox.Text);
					return;
				}
			}
			else
			{
				if (!(name == "txtKCoff"))
				{
					return;
				}
				this.userSettingInfo.KCoffie = Convert.ToDouble(textBox.Text);
				return;
			}
		}

		private void TextValidating(object sender, CancelEventArgs e)
		{
			if (!this.beChecked)
			{
				e.Cancel = false;
				return;
			}
			System.Windows.Forms.TextBox textBox = sender as System.Windows.Forms.TextBox;
			if (textBox == null)
			{
				return;
			}
			if (!this.BeNumber(textBox.Text))
			{
				YJKMessageBox.Show("输入应为数字！");
				e.Cancel = true;
				textBox.Focus();
				textBox.SelectAll();
				return;
			}
			if (!this.BeInSection01(textBox.Text))
			{
				YJKMessageBox.Show("输入数字应在0-1区间内，\n包含0，但不包含1。");
				e.Cancel = true;
				textBox.Focus();
				textBox.SelectAll();
				return;
			}
		}

		private bool ValidatingText()
		{
			bool flag = true;
			foreach (object obj in this.groupBox2.Controls)
			{
				System.Windows.Forms.TextBox textBox = obj as System.Windows.Forms.TextBox;
				if (textBox != null)
				{
					flag = this.JudgeTextValue(textBox);
					if (!flag)
					{
						return flag;
					}
				}
			}
			foreach (object obj2 in this.pnlSetting1.Controls)
			{
				System.Windows.Forms.TextBox textBox2 = obj2 as System.Windows.Forms.TextBox;
				if (textBox2 != null)
				{
					flag = this.JudgeTextValue(textBox2);
					if (!flag)
					{
						return flag;
					}
				}
			}
			foreach (object obj3 in this.pnlSetting2.Controls)
			{
				System.Windows.Forms.TextBox textBox3 = obj3 as System.Windows.Forms.TextBox;
				if (textBox3 != null)
				{
					flag = this.JudgeTextValue(textBox3);
					if (!flag)
					{
						return flag;
					}
				}
			}
			foreach (object obj4 in this.pnlSetting2.Controls)
			{
				System.Windows.Forms.TextBox textBox4 = obj4 as System.Windows.Forms.TextBox;
				if (textBox4 != null)
				{
					flag = this.JudgeTextValue(textBox4);
					if (!flag)
					{
						return flag;
					}
				}
			}
			return flag;
		}

		private bool JudgeTextValue(System.Windows.Forms.TextBox txtBox)
		{
			bool result = true;
			if (this.BeNumber(txtBox.Text))
			{
				YJKMessageBox.Show("输入应为数字！");
				return false;
			}
			string name = txtBox.Name;
			uint num = YArchitech.Revit.PrivateImplementationDetails.ComputeStringHash(name);
			if (num <= 1905503892u)
			{
				if (num <= 745439394u)
				{
					if (num <= 131564569u)
					{
						if (num != 126510829u)
						{
							if (num != 131564569u)
							{
								return result;
							}
							if (!(name == "txtColDis"))
							{
								return result;
							}
							goto IL_2A9;
						}
						else if (!(name == "txtRadius"))
						{
							return result;
						}
					}
					else if (num != 476523551u)
					{
						if (num != 745439394u)
						{
							return result;
						}
						if (!(name == "txtArcFirstDistance"))
						{
							return result;
						}
						goto IL_2A9;
					}
					else
					{
						if (!(name == "txtRowDis"))
						{
							return result;
						}
						goto IL_2A9;
					}
				}
				else if (num <= 1296091846u)
				{
					if (num != 1247899082u)
					{
						if (num != 1296091846u)
						{
							return result;
						}
						if (!(name == "txtRowSide"))
						{
							return result;
						}
						goto IL_2A9;
					}
					else
					{
						if (!(name == "txtRatio"))
						{
							return result;
						}
						goto IL_28D;
					}
				}
				else if (num != 1660662284u)
				{
					if (num != 1905503892u)
					{
						return result;
					}
					if (!(name == "txtOffset"))
					{
						return result;
					}
				}
				else
				{
					if (!(name == "txtSpNum"))
					{
						return result;
					}
					goto IL_2A9;
				}
			}
			else if (num <= 2695252219u)
			{
				if (num <= 2320115276u)
				{
					if (num != 2267048540u)
					{
						if (num != 2320115276u)
						{
							return result;
						}
						if (!(name == "txtPLDistance"))
						{
							return result;
						}
					}
					else
					{
						if (!(name == "txtColSide"))
						{
							return result;
						}
						goto IL_2A9;
					}
				}
				else if (num != 2455206200u)
				{
					if (num != 2695252219u)
					{
						return result;
					}
					if (!(name == "txtRowNum"))
					{
						return result;
					}
					goto IL_2A9;
				}
				else
				{
					if (!(name == "txtArcRatio"))
					{
						return result;
					}
					goto IL_28D;
				}
			}
			else if (num <= 3011848981u)
			{
				if (num != 2739456642u)
				{
					if (num != 3011848981u)
					{
						return result;
					}
					if (!(name == "txtColNum"))
					{
						return result;
					}
					goto IL_2A9;
				}
				else if (!(name == "txtKCoff"))
				{
					return result;
				}
			}
			else if (num != 3818623342u)
			{
				if (num != 4032281099u)
				{
					return result;
				}
				if (!(name == "txtMinDis"))
				{
					return result;
				}
				goto IL_2A9;
			}
			else
			{
				if (!(name == "txtArcDistance"))
				{
					return result;
				}
				goto IL_2A9;
			}
			if (!this.BeDouble(txtBox.Text))
			{
				YJKMessageBox.Show("输入数字应为正数！");
				return false;
			}
			return result;
			IL_28D:
			if (this.BeInSection01(txtBox.Text))
			{
				YJKMessageBox.Show("输入数字应在0-1范围内，\n包括0但不包含1.");
				return false;
			}
			return result;
			IL_2A9:
			if (this.BeInteger(txtBox.Text))
			{
				YJKMessageBox.Show("输入数字应为正整数！");
				result = false;
			}
			return result;
		}

		private void txtColDis_Validating(object sender, CancelEventArgs e)
		{
			if (!this.beChecked)
			{
				e.Cancel = false;
				return;
			}
			System.Windows.Forms.TextBox textBox = sender as System.Windows.Forms.TextBox;
			if (textBox == null)
			{
				return;
			}
			if (!this.BeNumber(textBox.Text))
			{
				YJKMessageBox.Show("输入应为数字！");
				e.Cancel = true;
				textBox.Focus();
				textBox.SelectAll();
				return;
			}
			if (!this.BeInteger(textBox.Text))
			{
				YJKMessageBox.Show("输入数字应为正整数！");
				e.Cancel = true;
				textBox.Focus();
				textBox.SelectAll();
				return;
			}
			string name = textBox.Name;
			if (name == "txtRowDis")
			{
				this.userSettingInfo.SectorMaxRow = Convert.ToInt32(textBox.Text);
				return;
			}
			if (name == "txtColDis")
			{
				this.userSettingInfo.SectorMaxCol = Convert.ToInt32(textBox.Text);
				return;
			}
			if (name == "txtMinDis")
			{
				this.userSettingInfo.SectorMinDis = Convert.ToInt32(textBox.Text);
				return;
			}
			if (name == "txtRowSide")
			{
				this.userSettingInfo.SectorMaxSideRow = Convert.ToInt32(textBox.Text);
				return;
			}
			if (!(name == "txtColSide"))
			{
				return;
			}
			this.userSettingInfo.SectorMaxSideCol = Convert.ToInt32(textBox.Text);
		}

		private void txtPLDistance_Validating(object sender, CancelEventArgs e)
		{
			if (!this.beChecked)
			{
				e.Cancel = false;
				return;
			}
			System.Windows.Forms.TextBox textBox = sender as System.Windows.Forms.TextBox;
			if (textBox == null)
			{
				return;
			}
			if (!this.BeNumber(textBox.Text))
			{
				YJKMessageBox.Show("输入应为数字！");
				e.Cancel = true;
				textBox.Focus();
				textBox.SelectAll();
				return;
			}
			if (!this.BeDouble(textBox.Text))
			{
				YJKMessageBox.Show("输入数字应为正数！");
				e.Cancel = true;
				textBox.Focus();
				textBox.SelectAll();
				return;
			}
		}

		private bool BeInteger(string textValue)
		{
			string pattern = "^[1-9]\\d*$";
			return Regex.IsMatch(textValue, pattern);
		}

		private bool BeNumber(string textValue)
		{
			string pattern = "^(-?\\d+)(\\.\\d+)?$";
			return Regex.IsMatch(textValue, pattern);
		}

		private bool BeDouble(string textValue)
		{
			string pattern = "^\\d+(\\.\\d+)?$";
			return Regex.IsMatch(textValue, pattern);
		}

		private bool BeInSection01(string textValue)
		{
			bool flag = this.BeNumber(textValue);
			if (flag)
			{
				double num = Convert.ToDouble(textValue);
				if (num < 0.0 || num >= 1.0)
				{
					flag = false;
				}
			}
			return flag;
		}

		private void cmbRCMultiple_SelectedIndexChanged(object sender, EventArgs e)
		{
			System.Windows.Forms.ComboBox comboBox = sender as System.Windows.Forms.ComboBox;
			this.userSettingInfo.Divisor = Convert.ToInt32(comboBox.SelectedItem);
		}

		private void cmbSprinklerType_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (this.currentBtn == 1)
			{
				this.Fsymbol = this.fsList.FirstOrDefault((FamilySymbol q) => q.Name == this.cmbSprinklerType.SelectedItem.ToString());
			}
			System.Windows.Forms.ComboBox comboBox = sender as System.Windows.Forms.ComboBox;
			this.userSettingInfo.FamilySymbolName = comboBox.SelectedItem.ToString();
		}

		private void ButtonLaySprinkler_Click(object sender, EventArgs e)
		{
			HVACUserSetting hvacuserSetting = new HVACUserSetting();
			this.SetUserInfoToDic();
			hvacuserSetting.WriteSectorLaySetting(this.dicUISetting);
		}

		private void txtRowDis_TextChanged(object sender, EventArgs e)
		{
		}

		private void SetUserInfoToDic()
		{
			this.dicUISetting.Clear();
			this.dicUISetting.Add(UserSettingName.familyCategory.ToString(), this.userSettingInfo.FamilyCategory.ToString());
			this.dicUISetting.Add(UserSettingName.familyName.ToString(), this.userSettingInfo.FamilyName);
			this.dicUISetting.Add(UserSettingName.familySymbolName.ToString(), this.userSettingInfo.FamilySymbolName);
			this.dicUISetting.Add(UserSettingName.drawRange.ToString(), this.userSettingInfo.DrawRange.ToString());
			this.dicUISetting.Add(UserSettingName.layStyle.ToString(), this.userSettingInfo.LayStyle);
			this.dicUISetting.Add(UserSettingName.limitedSector.ToString(), this.userSettingInfo.LimitedSector);
			this.dicUISetting.Add(UserSettingName.limitedArc.ToString(), this.userSettingInfo.LimitedArc);
			this.dicUISetting.Add(UserSettingName.divisor.ToString(), this.userSettingInfo.Divisor.ToString());
			this.dicUISetting.Add(UserSettingName.drawLength.ToString(), this.userSettingInfo.DrawLength.ToString());
			this.dicUISetting.Add(UserSettingName.dangerLevel.ToString(), this.userSettingInfo.DangerLevel);
			this.dicUISetting.Add(UserSettingName.sectorCol.ToString(), this.userSettingInfo.SectorCol.ToString());
			this.dicUISetting.Add(UserSettingName.sectorRow.ToString(), this.userSettingInfo.SectorRow.ToString());
			this.dicUISetting.Add(UserSettingName.sectorRatio.ToString(), this.userSettingInfo.SectorRatio.ToString());
			this.dicUISetting.Add(UserSettingName.arcNum.ToString(), this.userSettingInfo.ArcNum.ToString());
			this.dicUISetting.Add(UserSettingName.arcRatio.ToString(), this.userSettingInfo.ArcRatio.ToString());
			this.dicUISetting.Add(UserSettingName.arcDistance.ToString(), this.userSettingInfo.ArcDistance.ToString());
			this.dicUISetting.Add(UserSettingName.arcSide.ToString(), this.userSettingInfo.ArcSide.ToString());
			this.dicUISetting.Add(UserSettingName.offSet.ToString(), this.userSettingInfo.OffSet.ToString());
			this.dicUISetting.Add(UserSettingName.radius.ToString(), this.userSettingInfo.Radius.ToString());
			this.dicUISetting.Add(UserSettingName.kCoffie.ToString(), this.userSettingInfo.KCoffie.ToString());
			this.dicUISetting.Add(UserSettingName.isConn.ToString(), this.userSettingInfo.IsConn.ToString());
			this.dicUISetting.Add(UserSettingName.pipeType.ToString(), this.userSettingInfo.PipeType.ToString());
		}

		private void btnLay_Click(object sender, EventArgs e)
		{
			if (this.rdbArcDis.Checked && this.txtArcDistance.Text.ToDouble(0.0) <= this.txtArcFirstDistance.Text.ToDouble(0.0))
			{
				YJKMessageBox.Show("边距值必须小于间距值！");
				this.txtArcFirstDistance.Focus();
				this.txtArcFirstDistance.SelectAll();
				return;
			}
			this.userSettingInfo.SectorMaxRow = Convert.ToInt32(this.txtRowDis.Text);
			this.userSettingInfo.SectorMaxCol = Convert.ToInt32(this.txtColDis.Text);
			this.userSettingInfo.SectorMinDis = Convert.ToInt32(this.txtMinDis.Text);
			this.userSettingInfo.SectorMaxSideRow = Convert.ToInt32(this.txtRowSide.Text);
			this.userSettingInfo.SectorMaxSideCol = Convert.ToInt32(this.txtColSide.Text);
			this.userSettingInfo.FamilyID = this.familyID;
			this.SetUserInfoToDic();
			new HVACUserSetting().WriteSectorLaySetting(this.dicUISetting);
			base.DialogResult = DialogResult.Yes;
		}

		private void btnCancel_MouseEnter(object sender, EventArgs e)
		{
			this.beChecked = false;
		}

		private void btnCancel_MouseLeave(object sender, EventArgs e)
		{
			this.beChecked = true;
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		private void rdoConn_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rdoConn.Checked && this.rdbSector.Checked)
			{
				this.userSettingInfo.IsConn = 0;
				this.cbxPipeType.Enabled = true;
				this.txtPLDistance.Enabled = true;
			}
		}

		private void rdoUnConn_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rdoUnConn.Checked)
			{
				this.userSettingInfo.IsConn = 1;
				this.cbxPipeType.Enabled = false;
				this.txtPLDistance.Enabled = false;
			}
		}

		private void cbxPipeType_SelectedIndexChanged(object sender, EventArgs e)
		{
			this.userSettingInfo.PipeType = this.cbxPipeType.SelectedIndex;
		}

		public int CurrentBtn
		{
			get
			{
				return this.currentBtn;
			}
		}

		public FamilySymbol Fsymbol { get; set; }

		private void tvwProject_AfterSelect(object sender, TreeViewEventArgs e)
		{
			if (this.tvwProject.SelectedNode == null)
			{
				return;
			}
			this.tvwProject.SelectedNode.BackColor = System.Drawing.Color.DodgerBlue;
			this.tvwProject.SelectedNode.ForeColor = System.Drawing.Color.White;
			if (this.tvwProject.SelectedNode.Level == 0)
			{
				this.cmbSprinklerType.Items.Clear();
				return;
			}
			Family family = this.tvwProject.SelectedNode.Tag as Family;
			this.cmbSprinklerType.Items.Clear();
			this.fsList.Clear();
			this.fsList = family.GetSymbols();
			if (this.fsList.Count < 1)
			{
				return;
			}
			foreach (FamilySymbol familySymbol in this.fsList)
			{
				this.cmbSprinklerType.Items.Add(familySymbol.Name);
			}
			this.cmbSprinklerType.SelectedIndex = 0;
		}

		private void tvwProject_BeforeSelect(object sender, TreeViewCancelEventArgs e)
		{
			if (this.tvwProject.SelectedNode != null)
			{
				this.tvwProject.SelectedNode.BackColor = System.Drawing.Color.White;
				this.tvwProject.SelectedNode.ForeColor = System.Drawing.Color.Black;
			}
		}

		private void btnHy_Click(object sender, EventArgs e)
		{
			this.TxtFamilyNameTextChanged();
			this.btnHy.BackColor = System.Drawing.Color.White;
			this.currentBtn = 0;
			this.btnproj.BackColor = System.Drawing.Color.Transparent;
			this.panelHy.Visible = true;
			this.panelProj.Visible = false;
		}

		private void btnproj_Click(object sender, EventArgs e)
		{
			this.btnHy.BackColor = System.Drawing.Color.Transparent;
			this.currentBtn = 1;
			this.btnproj.BackColor = System.Drawing.Color.White;
			this.panelHy.Visible = false;
			this.panelProj.Visible = true;
			if (this.tvwProject.SelectedNode != null)
			{
				if (this.tvwProject.SelectedNode == this.tvwProject.TopNode)
				{
					this.cmbSprinklerType.Items.Clear();
					return;
				}
				TreeNode selectedNode = this.tvwProject.SelectedNode;
				this.tvwProject.SelectedNode = this.tvwProject.Nodes[0];
				if (this.tvwProject.Nodes[0].Nodes.Count < 1)
				{
					return;
				}
				this.tvwProject.SelectedNode = selectedNode;
				return;
			}
			else
			{
				this.tvwProject.SelectedNode = this.tvwProject.Nodes[0];
				if (this.tvwProject.Nodes[0].Nodes.Count < 1)
				{
					return;
				}
				this.tvwProject.SelectedNode = this.tvwProject.Nodes[0].Nodes[0];
				return;
			}
		}

		private int familyID;

		private SpaceFamilyDataReader dataReader = new SpaceFamilyDataReader();

		private List<DangerItem> listDangerLevels = new List<DangerItem>();

		private List<ListItem> familyInfos = new List<ListItem>();

		private Dictionary<string, string> dicUISetting = new Dictionary<string, string>();

		public UserSettedInfo userSettingInfo = new UserSettedInfo();

		private int loadNum;

		private bool beChecked = true;

		private Document doc;

		private int currentBtn;

		private List<FamilySymbol> fsList = new List<FamilySymbol>();
	}
}
